﻿using Cofe.Core.Property;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cofe.Core.Filter
{
    [EntryFilter("or")]
    public class OrEntryFilter : EntryFilterBase, IMultiEntryFilter
    {        
        public OrEntryFilter(params IEntryFilter[] filters)
            : base("OR","OR")
        {
            _entryFilters = new List<IEntryFilter>(filters);
            SupportedMatchType = MatchType.All;
        }

        //private IEntryFilter _filter1, _filter2;

        public override MatchType matches(IPropertyHost entry,
            params IOptionFilter[] options)
        {
            MatchType matchType = MatchType.None;

            foreach (var f in EntryFilters)
                matchType |= f.Matches(entry, options);

            return matchType;            
        }


        private List<IEntryFilter> _entryFilters;
        public override string Type { get { return "OR"; } }
        public IEntryFilter[] EntryFilters { get { return _entryFilters.ToArray(); } }



        public void AddEntryFilter(IEntryFilter filter)
        {
            _entryFilters.Add(filter);
        }
    }
}
